import { productDisable, productDelete } from '@/api/goodsInfo'
import { ref } from 'vue'
import { EnableOrDisableOrDeleteRes } from './types'

const useProduct = () => {
  const productMultipleDisableLoading = ref(false)
  const productMultipleDisable = async (productIds: Array<string>) => {
    productMultipleDisableLoading.value = true
    const res = await productDisable(productIds, true)
    productMultipleDisableLoading.value = false
    return res.data as EnableOrDisableOrDeleteRes
  }

  const productMultipleEnableLoading = ref(false)
  const productMultipleEnable = async (productIds: Array<string>) => {
    productMultipleEnableLoading.value = true
    const res = await productDisable(productIds, false)
    productMultipleEnableLoading.value = false
    return res.data as EnableOrDisableOrDeleteRes
  }

  const productMultipleDeleteLoading = ref(false)
  const productMultipleDelete = async (productIds: Array<string>) => {
    productMultipleDeleteLoading.value = true
    const res = await productDelete(productIds)
    productMultipleDeleteLoading.value = false
    return res.data as EnableOrDisableOrDeleteRes
  }

  return {
    productMultipleEnableLoading,
    productMultipleDeleteLoading,
    productMultipleDisableLoading,
    productMultipleDelete,
    productMultipleEnable,
    productMultipleDisable,
  }
}

export default useProduct
